﻿using System;
using System.Runtime.CompilerServices;

namespace Helpers
{
    public static class LoggerHelper
    {
        public static Action<object> OnLogInformation;
        public static Action<object> OnLogError;
        public static void LogInformation(object msg, [CallerMemberName]string memberName = "", [CallerFilePath]string sourceFilePath = "", [CallerLineNumber]int sourceLineNumber = 0)
        {
            try
            {
                var temp = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}|INFO|{memberName}|{msg}";
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(temp);
                Console.ForegroundColor = ConsoleColor.White;
                OnLogInformation?.Invoke(temp);
            }
            catch (Exception)
            {
            }
        }

        public static void LogError(Exception ex, [CallerMemberName]string memberName = "", [CallerFilePath]string sourceFilePath = "", [CallerLineNumber]int sourceLineNumber = 0)
        {
            try
            {
                var temp = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}|ERROR|{memberName}|{ex.GetType().Name}|{ex.Message}";
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine(temp);
                Console.ForegroundColor = ConsoleColor.White;
                OnLogError?.Invoke(temp);
            }
            catch (Exception)
            {
            }
        }
    }
}
